/*
 * 天虹商场股份有限公司版权所有.
 */
package com.rainbow.formework.beans;

import com.rainbow.formework.aop.HMKAopConfig;
import com.rainbow.formework.aop.HMKAopProxy;

/**
 * TODO
 *
 * @author 黄明坤
 * @version 1.0.0
 * @date 2020/7/3
 */
public class HMKBeanWrapper {

    private HMKAopProxy aopProxy = new HMKAopProxy();



    //还会用到  观察者  模式
    //1、支持事件响应，会有一个监听
    private HMKBeanPostProcessor postProcessor;
    //代理类
    private Object wrapperInstance;
    //原始的通过反射new出来，要把包装起来，存下来
    private Object originalInstance;



    public HMKBeanPostProcessor getPostProcessor() {
        return postProcessor;
    }

    public void setPostProcessor(HMKBeanPostProcessor postProcessor) {
        this.postProcessor = postProcessor;
    }

    public HMKBeanWrapper(Object instance){
        //从这里开始，我们要把动态的代码添加进来了
        this.wrapperInstance = aopProxy.getProxy(instance);
        this.originalInstance = instance;
    }

    public Object getWrappedInstance(){
        return this.wrapperInstance;
    }


    // 返回代理以后的Class
    // 可能会是这个 $Proxy0
    public Class<?> getWrappedClass(){
        return this.wrapperInstance.getClass();
    }


    public void setAopConfig(HMKAopConfig config){
        aopProxy.setConfig(config);
    }


    public Object getOriginalInstance() {
        return originalInstance;
    }

}
